#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)  
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
using std::vector;

const int N = 3e3+10;
int _,n,a[2*N];
ll ans;

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> _;
    while(_--){
        ans = 0;
        cin >> n;
        vector<int> t((n+1)*(n+1));
        rep(i,1,n) cin >> a[i];
        rep(i,1,n) --a[i];
        std::fill(t.begin(),t.end(),0);
        per(i,n-1,3){
            rep(j,i+1,n) ++t[ a[i]*n + a[j] ];
            rep(j,1,i-2) ans += t[ a[j]*n + a[i-1] ];
        }
        cout << ans << "\n";
    }
    return 0;
}